package com.ctw.mall.controller;

import com.ctw.mall.service.IProductService;
import com.ctw.mall.vo.ProductDetailVo;
import com.ctw.mall.vo.ResponseVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController {

    @Autowired
    private IProductService productService;

    @GetMapping("/products")
    public ResponseVo<PageInfo> list(@RequestParam(required = false) Integer categoryId,
                                     @RequestParam(required = false,defaultValue = "1")  Integer pageNum,   //默认值设置只能是字符
                                     @RequestParam(required = false,defaultValue = "10") Integer pageSize){

        return productService.list(categoryId,pageNum,pageSize);
    }


    //在拦截器中路径为"/products/*"
    @GetMapping("/products/{productId}")
    public ResponseVo<ProductDetailVo> detail(@PathVariable Integer productId){


        return productService.detail(productId);
    }
}
